package prototype;

import java.io.*;
import java.util.Date;

public class Qitiandasheng extends Monkey implements Cloneable, Serializable {
    public Jingubang jingubang;


    public Qitiandasheng() {
        this.birthday = new Date(2020,9,5);
        this.jingubang = new Jingubang();
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return this.deepClone();
    }

    public Object deepClone() {
        try{

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(this);

            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);
            Qitiandasheng clone = (Qitiandasheng) ois.readObject();
            clone.birthday = new Date();
            return clone;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    public Qitiandasheng shallowClone() {
        Qitiandasheng clone = new Qitiandasheng();
        clone.height = this.height;
        clone.weight = this.weight;
        clone.jingubang = this.jingubang;
        clone.birthday = new Date();
        return clone;
    }

}
